#include "scr_camera.h"
#include "scr_game.h"
#include "scr_rect.h"

SCRCamera::SCRCamera()
	: m_X(0)
	, m_Y(0)
	, m_Bounds(0, 0, SCRGame::SCR_SCREEN_WIDTH, SCRGame::SCR_SCREEN_HEIGHT)
{
}

bool SCRCamera::IsInView(const int& X, const int& Y)
{
	SCRRect Rect(m_X, m_Y, SCRGame::SCR_SCREEN_WIDTH, SCRGame::SCR_SCREEN_HEIGHT);
	
	return Rect.Intersect(X, Y);
}

bool SCRCamera::IsInView(const SCRRect& Rect)
{
	SCRRect CameraRect(m_X, m_Y, SCRGame::SCR_SCREEN_WIDTH, SCRGame::SCR_SCREEN_HEIGHT);

	return CameraRect.Intersect(Rect);
}

void SCRCamera::ApplyOffset(const int& OffsetX, const int& OffsetY)
{
	m_X += OffsetX;
	m_Y += OffsetY;

	if (m_X < m_Bounds.m_X)
	{
		m_X = m_Bounds.m_X;
	}

	if (m_Y < m_Bounds.m_Y)
	{
		m_Y = m_Bounds.m_Y;
	}

	const int BoundsX = (m_Bounds.m_X + m_Bounds.m_Width) - SCRGame::SCR_SCREEN_WIDTH;
	if (m_X > BoundsX)
	{
		m_X = BoundsX;
	}

	const int BoundsY = (m_Bounds.m_Y + m_Bounds.m_Height) - SCRGame::SCR_SCREEN_HEIGHT;
	if (m_Y > BoundsY)
	{
		m_Y = BoundsY;
	}
}
